<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>店铺页</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }

        table, tr, th, td {
            border: 1px solid #5fbdcb;
        }

        table {
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    <table></table>
    <dl>
        <dt><a href="" id="a1">修改店铺信息</a></dt>
        <dt><a href="" id="a2">查看菜品</a></dt>
        <dt><a href="" id="a3">查看评论</a></dt>
        <dt><a href="" id="a4">查看已完成订单</a></dt>
        <dt><a href="" id="a5">查看待处理的订单</a></dt>
        <dt><a href="" id="a6">设置优惠券</a></dt>
    </dl>
    <a href="SellerPage.jsp">返回</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    let storeId = null;
    $(function () {
        $.ajax({
            url: "http://localhost:8080/ban.do",
            type: "post",
            data: {
                method: 'judgeBan'
            },
            dataType: "text",
            success: function (data) {
                if (data === "error") {
                    alert("您被封禁，不能操作店铺");
                    window.location.href = 'SellerPage.jsp';
                }
            }
        })
        $.ajax({
            url: "http://localhost:8080/user.do",
            type: "post",
            data: {
                method: 'store'
            },
            dataType: "text",
            success: function (data) {
                console.log(data);
                let parse = JSON.parse(data);
                if (parse === null) {
                    alert("您还没有创建店铺，请先创建");
                    window.location.href = 'CreateStore.jsp';
                } else {
                    storeId = parse.storeId;
                    let table = document.querySelector('table');
                    let tr = document.createElement('tr');
                    table.appendChild(tr);
                    let th1 = document.createElement('th');
                    tr.appendChild(th1);
                    th1.innerText = '店铺名';
                    let td1 = document.createElement('td');
                    tr.appendChild(td1);
                    td1.innerText = parse.storeName;
                    let th2 = document.createElement('th');
                    tr.appendChild(th2);
                    th2.innerText = '菜品数';
                    let td2 = document.createElement('td');
                    tr.appendChild(td2);
                    td2.innerText = parse.dishNum;
                    let th3 = document.createElement('th');
                    tr.appendChild(th3);
                    th3.innerText = '评论数';
                    let td3 = document.createElement('td');
                    tr.appendChild(td3);
                    td3.innerText = parse.commentNum;
                    let th4 = document.createElement('th');
                    tr.appendChild(th4);
                    th4.innerText = '简介';
                    let td4 = document.createElement('td');
                    tr.appendChild(td4);
                    td4.innerText = parse.introduce;
                    let th5 = document.createElement('th');
                    tr.appendChild(th5);
                    th5.innerText = '完成订单';
                    let td5 = document.createElement('td');
                    tr.appendChild(td5);
                    td5.innerText = parse.processOrderNum;
                    let th6 = document.createElement('th');
                    tr.appendChild(th6);
                    th6.innerText = '未完成订单';
                    let td6 = document.createElement('td');
                    tr.appendChild(td6);
                    td6.innerText = parse.unProcessOrderNum;
                    let th7 = document.createElement('th');
                    tr.appendChild(th7);
                    th7.innerText = '营业额';
                    let td7 = document.createElement('td');
                    tr.appendChild(td7);
                    td7.innerText = parse.turnover;
                    let th8 = document.createElement('th');
                    tr.appendChild(th8);
                    th8.innerText = '状态';
                    let td8 = document.createElement('td');
                    tr.appendChild(td8);
                    if (parse.unProcessOrderNum === 0) {
                        td8.innerText = '等待审核中';
                    } else {
                        td8.innerText = '已上线';
                    }
                }
            }
        })
        $('#a1').on("click",function () {
            this.href = 'ModifyStore.jsp?storeId='+storeId;
        })
        $('#a2').on("click",function () {
            this.href = 'SellerDishPage.jsp?storeId='+storeId;
        })
        $('#a3').on("click",function () {
            this.href = 'SellerCommentPage.jsp?storeId='+storeId;
        })
        $('#a4').on("click",function () {
            this.href = 'ProcessOrderPage.jsp?storeId='+storeId;
        })
        $('#a5').on("click",function () {
            this.href = 'UnProcessOrderPage.jsp?storeId='+storeId;
        })
        $('#a6').on("click",function () {
            this.href = 'SellerCoupon.jsp?storeId='+storeId;
        })
    })
</script>
</body>
</html>
